package com.ysd.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.News;
import com.ysd.utli.DBManager;

public class NewsDaolmpl {
	public List<News> getNewsList(int nId){
		List<News> list = new ArrayList<News>();
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			String sql = "SELECT * FROM news WHERE newsCategoryid="+nId;//ͨ������������Ѷ��������ȥ��Ӧ��������Ѷ����
			rs = st.executeQuery(sql);
			while(rs.next()) {
				int newsid = rs.getInt("newsid");
				String newsTitle = rs.getString("newsTitle");
				String newsContent = rs.getString("newsContent");
				String newsCategoryid = rs.getString("newsCategoryid");
				String newsZhuYe = rs.getString("newsZhuYe");
				News news =new News(newsid, newsTitle, newsContent, newsCategoryid, newsZhuYe);
				list.add(news);
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
//	public List<News> getNewList1(){
//		List<News> list = new ArrayList<News>();
//		Connection conn = DBManager.getConnection();
//		Statement st = null;
//		ResultSet rs = null;
//		try {
//			st = conn.createStatement();
//			String sql = "SELECT * FROM news WHERE newsCategoryid=1";//ͨ������������Ѷ��������ȥ��Ӧ��������Ѷ����
//			rs = st.executeQuery(sql);
//			while(rs.next()) {
//				int newsid = rs.getInt("newsid");
//				String newsTitle = rs.getString("newsTitle");
//				String newsContent = rs.getString("newsContent");
//				String newsCategoryid = rs.getString("newsCategoryid");
//				String newsZhuYe = rs.getString("newsZhuYe");
//				News news =new News(newsid, newsTitle, newsContent, newsCategoryid, newsZhuYe);
//				list.add(news);
//			}
//			return list;
//		} catch (SQLException e) {
//			e.printStackTrace();
//			return null;
//		}finally {
//			DBManager.closeAll(conn, st, rs);
//		}
//		
//	}
	/** 
	 * 删除
	 */
	public int deleteNewsId(int nsId) {
		return DBManager.executeUpdate("DELETE FROM news WHERE newsid="+nsId);
	}

}
